<template>
  <el-card class="box-card">
    <template #header>
      条件查询
    </template>
    <el-form :model="form" :rules="rules" ref="ruleFormRef" inline>
      <el-form-item label="起始日期">
        <lay-date-picker v-model="form.startTime" allowClear placeholder="请选择开始日期" />
      </el-form-item>
      <el-form-item label="结束日期">
        <lay-date-picker v-model="form.endTime" type="date" placeholder="请选择结束日期" />
      </el-form-item>
     
      <template v-if="isShow">
        <el-form-item>
          <lay-select v-model="form.开单科室" filterable placeholder="开单科室">
            <lay-select-option v-for="item in rulesSearch?.开单科室" :key="item" :label="item" :value="item" />
          </lay-select>
        </el-form-item>
        <el-form-item>
          <lay-select  v-model="form.执行科室" filterable placeholder="执行科室">
            <lay-select-option v-for="item in rulesSearch?.执行科室" :key="item" :label="item" :value="item" />
          </lay-select >
        </el-form-item>
        <el-form-item>
          <lay-select  v-model="form.收费代码" filterable placeholder="收费代码">
            <lay-select-option v-for="item in rulesSearch?.收费代码" :key="item" :label="item" :value="item" />
          </lay-select >
        </el-form-item>
        <el-form-item>
          <lay-select  v-model="form.项目名称" filterable placeholder="项目名称">
            <lay-select-option v-for="item in rulesSearch?.项目名称" :key="item" :label="item" :value="item" />
          </lay-select >
        </el-form-item>
      </template>
      <el-form-item>
        <lay-button type="primary" @click="getDate(ruleFormRef)"> 查询 </lay-button>
        <lay-button type="warning" @click="clear">重置</lay-button>
      </el-form-item>

    </el-form>
  </el-card>
</template>

<script setup>
import { ref } from 'vue'
import { getSearch_rules } from '@/api/Benefit.js'

const form = ref({
  startTime: 1672502400000,
  endTime: new Date().getTime(),
})
const rules = ref({
  endTime: [{
    required: true,
    type: 'date',
    message: '请选择时间',
    trigger: 'change',
  }]
})
const ruleFormRef = ref(null)
const emits = defineEmits(['submit'])

const props = defineProps({
  isShow: {
    type: Boolean,
    default: true
  }
})
const getDate = async (ruleFormRef) => {
  if (!ruleFormRef) return
  await ruleFormRef.validate((valid, fields) => {
    if (valid) {
      form.value.startTime = new Date(form.value.startTime).getTime()
      form.value.endTime = new Date(form.value.endTime).getTime()
      emits('submit', form.value)
    } else {
      console.log('err')
    }
  })
}

const clear = () => {
  form.value = {}
  form.value = {
    startTime: 1672502400000,
    endTime: new Date().getTime(),
  }
  emits('submit', form.value)
}

const rulesSearch = ref({})
const getRules = async () => {
  const res = await getSearch_rules()
  rulesSearch.value = res.data
}
getRules()
</script>

<style scoped lang="less"></style>